#include <stdio.h>
#include <string.h>

int main()
{
    char str[100];
    printf("请输入一行字符: \n");
    fgets(str, sizeof(str), stdin);

    int maxLength = 0; // 最长单词的长度
    int start = 0; // 最长单词的起始位置
    int count = 0; // 当前单词的长度
    int i;
    for (i = 0; str[i] != '\0'; i++) {
        if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) {
            count++;
        } else {
            if (count > maxLength) {
                maxLength = count;
                start = i - count;
            }
            count = 0;
        }
    }
/*
    // 最后一个单词的长度可能会比前面的单词长，需要再次比较一次长度
    if (count > maxLength) {
        maxLength = count;
        start = i - count;
    }
*/
    printf("最长的单词是: ");
    for (i = start; i < start + maxLength; i++) {
        printf("%c", str[i]);
    }
    printf("\n");

    return 0;
}